<?php
namespace api\modules\v1\controllers;

use api\modules\v1\models\redPacket\ReceiveRedPacket;
use api\modules\v1\models\redPacket\RedPacket;
use api\modules\v1\models\redPacket\RedPacketLog;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;
use Yii;

class RedPacketController extends DefaultController
{
    public $modelClass = 'api\modules\v1\models\user\User';
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' => HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法

                ]
            ]
        ]);
    }
    /* ====================== 发送红包 ========================= */
    public function actionSend() {
        if (Yii::$app->request->isPost) {
            return (new RedPacket())->send();
        }
    }

    /* ====================== 领取红包 ========================= */
    public function actionReceive() {
        if (Yii::$app->request->isPost) {
            return (new ReceiveRedPacket())->receiveRePacket();
        }
    }


    # 获取红包状态
    public function actionState($id = 0) {
        if (Yii::$app->request->isGet) {
            return (new RedPacket())->state($id);
        }
    }

    # 红包领取记录
    public function actionReceiveList($id = 0) {
        if (Yii::$app->request->isGet) {
            return (new RedPacketLog())->getReceiveList($id);
        }
    }

    # 红包记录
    public function actionLogList() {
        if (Yii::$app->request->isGet) {
            return (new RedPacketLog())->getList();
        }
    }

}


